import { List } from 'antd';
import { MessageOutlined, LikeOutlined, StarOutlined } from '@ant-design/icons';
import { Link, connect } from 'umi';

class CatePage extends React.Component {
    constructor(props) {
        super(props)
        this.state = {
            loading: true,
            dataSource: [],
        }
    }
    componentDidMount() {
        this.fetchCate();
    }
    fetchCate = () => {
        this.setState({ loading: true });
        this.props.dispatch({
            type: 'Category/getTreeList',
            payload: { layout: 'article', parentId: 1 }
        }).then(() => {
            this.setState({ loading: false, dataSource: this.props.Category.response.result });
        })
    }
    render() {
        return (
            <>
                <List
                    loading={this.state.loading}
                    size="large"
                    dataSource={this.state.dataSource}                    
                    renderItem={item => (
                        <List.Item key={item.id} >
                            <a onClick={()=>this.props.getData(item.id)}>{item.categoryName}</a>
                        </List.Item>
                    )}
                />
            </>
        )
    }
}

export default connect(({ user, Category }) => ({
    currentUser: user.currentUser,
    Category,
}))(CatePage);